package com.china08.yxyapi.api.manage.edu.platform.lesson.catalog;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.china08.yxyapi.api.YxyApiBaseController;
import com.china08.yxyapi.entity.db.lessons.cloud.YxyLessonsCloudCatalog;
import com.china08.yxyapi.model.YxyApiReqModel;
import com.china08.yxyapi.repository.db.lesson.YxyLessonsCloudCatalogRepository;

import io.swagger.annotations.ApiOperation;

@CrossOrigin
@RestController
public class EduLessonCatalogUpdOrderController extends YxyApiBaseController {

    @Autowired
    YxyLessonsCloudCatalogRepository catalogRepository;

    @ApiOperation(value = "")
    @RequestMapping(value = "/api_yw/manage/edu/platform/lesson/catalog/upd/ordernum", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public void precess(HttpServletRequest request, HttpServletResponse response, @RequestBody ReqModel reqModel) {
        String catalogId = reqModel.catalogId;
        Integer orderNum = reqModel.orderNum;

        YxyLessonsCloudCatalog catalog = catalogRepository.findById(catalogId);
        if (catalog != null) {
            catalog.setOrderNum(orderNum);
            catalogRepository.saveAndFlush(catalog);
        }
    }

    public static class ReqModel extends YxyApiReqModel {
        public String catalogId;
        public Integer orderNum;

        @Override
        public void autoCheck() {

        }
    }

}
